// import { getEventHistory, getEventDict, getEventChinese } from '@/api/event'
import selectfence from "./fence/index";
import { getFormatDate, getFormatHourMinute, getFormatDateTime, getFormatDateTime_2 } from '@/utils/datetime'
import checkfence from "./fence/index_checkfence";
import { getWorkAreaFence, updateTaskInfo, deleteTaskInfo, postfenceTrack, getSectionData, getLineData, getImagePaths, getTaskInfo, getTaskBriefList, getUserInfobyPage, getDeviceInfobyPage, getUserGroupInfobyPage, getDeviceGroupInfobyPage, postTaskInfo, putTaskOperate } from '@/api/task'
export default {
  components: { selectfence, checkfence },
  data() {
    return {
      require: {
        //需要订阅的频道放在这里
        channels: [],
        //发出申请的组件名字放在这里
        component: 'task'
      },
      delete_taskid: '',
      edit_taskid: '',
      workAreaFenceMap: '',
      resetoptions: 0,
      checkpicture_taskid: '',
      autoCreateFenceDialog: false,
      autoCreateFence: true,
      checkpicture: false,
      picture_length: false,
      select_state: [],
      newData: [],
      twoData: [],
      fenceid: '',
      pagesize: 10,
      currentPage: 1,
      timeRange: [],
      choose_task_type: [],
      choose_task_state: '',
      choose_time_type: '',
      checktaskid: '',
      openCheckFence_create: false,
      checkfenceid: '',
      fenceid_traincheck: '',
      TimeTypeError: false,
      TimeRangeError: false,
      createtasksuccess: false,
      updatetasksuccess: false,
      deletetasksuccess: false,
      createtaskfailed: false,
      updatetaskfailed: false,
      deletetaskfailed: false,
      gettaskfailed: false,
      cannotupdatetask: false,
      cannotdeletetask: false,

      checkUserDialog: false,
      updateUserDialog: false,
      openSelectFence: false,
      openFenceType: false,
      openCheckFence: false,
      workAreaPicker: {
        fenceid: '',
        dropdown1: {
          select: 0,
          options: [
            { text: '请选择车站区间', value: 0 },
            { text: '车站', value: 1 },
            { text: '区间', value: 2 }
          ]
        },
        dropdown2: { select: 0, options: [{ text: '请选择', value: 0 }] },
        dropdown3: { select: 0, options: [{ text: '请选择', value: 0 }] }
      },
      //baseURL: 'http://152.136.13.167:9527',
      showViewer: true,
      picFileList: {},
      tableData: [],
      requestState: false,
      form_one: false,
      openSelectTrack: false,
      openSelectArea: false,
      form_two: false,
      form_three: false,
      selectfence_way: '',
      selectFenceType: '',
      selectFenceArea: '',
      start_kilometer_1: '',
      start_meter_1: '',
      end_kilometer_1: '',
      end_meter_1: '',
      location_supplied_1: '',
      location_supplied_2: '',
      location_supplied_3: '',
      switch_value1: '',
      station_list2: 1,
      station_lists_1: 1,
      station_lists_2: [{}, {}],
      station_lists_3: [{}],
      props: { multiple: true },
      one_input_1: '',
      one_input_2: '',
      two_input_1: '',
      two_input_2: '',
      three_input_1: '',
      three_input_2: '',
      handler: '请选择',
      person_options: [{ 'label': '正在获取', }, { 'label': '正在获取', }],
      person_options_2: [{ 'label': '正在获取', }, { 'label': '正在获取', }, { 'label': '正在获取', }, { 'label': '正在获取', }],
      person_lists3_2: 1,
      person_lists4_2: 1,
      person_lists3_3: 1,
      person_lists4_3: 1,
      loading: false,
      ruleForm: {
        name: '',
        region: '',
        area: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: '',
        manager: '',
        safeman: '',
        liaison: '',
        worker: '',
        petrolman: '',
        trainChecker: '',
      },
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        manager: [
          { required: true, message: '请选择负责人', trigger: 'change' }
        ],
        safeman: [
          { required: true, message: '请选择防护员', trigger: 'change' }
        ],
        liaison: [
          { required: true, message: '请选择联络员', trigger: 'change' }
        ],
        worker: [
          { required: true, message: '请选择相关人员', trigger: 'change' }
        ],
        petrolman: [
          { required: true, message: '请选择相关人员', trigger: 'change' }
        ],
        trainChecker: [
          { required: true, message: '请选择相关人员', trigger: 'change' }
        ],
        area: [
          { required: true, message: '请选择作业地点', trigger: 'change' }
        ],
        date1: [
          { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
        ],
        date2: [
          { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
        ],
        type: [
          { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
        ],
        resource: [
          { required: true, message: '请选择活动资源', trigger: 'change' }
        ],
        desc: [
          { required: true, message: '请填写活动形式', trigger: 'blur' }
        ]
      },

      currentPage: 1,
      tableData_length: 0,
      createUserDialog: false,
      choosed: '',
      totalDataLength: 0,
      timeRanges: null,
      loading: true,
      globalEventTableData: [],
      globalEventTableDataAll: [],
      singleEventTableData: [],
      singleEventTableDataAll: [],
      eventDict: [],
      eventNames: [],
      eventId: 1,
      startTime: '',
      endTime: '',
      queryData: {
        startTime: '',
        endTime: '',
        eventId: 1
      },
      filters: [],
      filter: {
        text: '',
        value: ''
      },
      test: 0,
      tableHeight: 0
    }
  },
  created() {
    this.getEventHistory()
    this.getEventChinese()
  },
  mounted() {
    this.getUserInfo(1, 100)
    this.getUserGroupInfo(1, 100)
    this.getDeviceInfo(1, 100)
    this.getDeviceGroupInfo(1, 100)
    setTimeout(this.delaydelete, 30000)
    this.getData()
    this.searchEvents2()

    // this.fenceid=this.$route.query.fenceid,
    // // this.createUserDialog=this.$route.query.createUserDialog,
    // this.choosed=this.$route.query.choosed
    // this.form_one=this.$route.query.form_one,
    // this.ruleForm.date1=this.$route.query.ruleForm.date1,
    // this.switch_value1=this.$route.query.switch_value1,
    // this.ruleForm.date2=this.$route.query.ruleForm.date2,
    // this.ruleForm.area=this.$route.query.ruleForm.area,
    // this.one_input_1=this.$route.query.one_input_1,
    // this.two_input_1=this.$route.query.two_input_1,
    // this.ruleForm.manager=this.$route.query.ruleForm.manager,
    // this.ruleForm.liaison=this.$route.query.ruleForm.liaison,
    // this.ruleForm.safeman=this.$route.query.ruleForm.safeman,
    // this.ruleForm.worker=this.$route.query.ruleForm.worker,
    // this.ruleForm.area=this.$route.query.ruleForm.area
    // this.start_kilometer_1=this.$route.query.start_kilometer_1
    // this.start_meter_1=this.$route.query.start_meter_1
    // this.end_kilometer_1=this.$route.query.end_kilometer_1
    // this.end_meter_1=this.$route.query.end_meter_1
    // this.location_supplied_1=this.$route.query.location_supplied_1


    this.$nextTick(() => {
      // 根据浏览器高度设置初始高度
      this.tableHeight = window.innerHeight - this.$refs.refsTable.$el.offsetTop - 150
      // 监听浏览器高度变化，修改表格高度
      window.onresize = () => {
        this.tableHeight = window.innerHeight - this.$refs.refsTable.$el.offsetTop - 150
      }
    })

    this.require.channels.push('TaskChangeBriefInfo')
    this.$bus.$emit('Subscribe', this.require)
    // 接收数据
    this.sockets.subscribe('TaskChangeBriefInfo', res => {
      for (var i = 0; i < this.tableData.length; i++)
        if (res.props.type == 'update')
          if (this.tableData[i].taskid == res.data.taskId) {
            if (res.data.type == 1)
              this.tableData[i].type = '工务作业'
            if (res.data.type == 2)
              this.tableData[i].type = '电务作业'
            if (res.data.type == 3)
              this.tableData[i].type = '巡道作业'
            if (res.data.type == 5)
              this.tableData[i].type = '其它作业'
            if (res.data.type == 4)
              this.tableData[i].type = '列检作业'
            if (res.data.type == 6)
              this.tableData[i].type = '机务作业'
            if (res.data.type == 7)
              this.tableData[i].type = '调车作业'
            if (res.data.type == 8)
              this.tableData[i].type = '商检作业'
            if (res.data.state == 3)
              this.tableData[i].state = 'startTask'
            else if (res.data.state == 5)
              this.tableData[i].state = 'endTask'
            else this.tableData[i].state = '已结束'
          }
    })

  },
  updated() {
  },
  destroyed() {
    this.$bus.$emit('Unsubscribe', this.require)
    // 关闭接收数据

  },
  computed: {},
  methods: {
    reFreshHtml() {
      this.$router.go(0)
    },
    filterChange(filters) {
      this.newData = []

      {
        this.loading = true
        // this.getEventHistory()
        // this.currentPage = 1
        // this.$refs.refsTable.clearFilter()
        this.timeRange = []
        this.timeRange[0] = this.timeRanges[0].getTime()
        this.timeRange[1] = this.timeRanges[0].getTime()
        var data = {
          timeRange: this.timeRange
        }

        getTaskBriefList(data).then((response) => {
          if (response.code == 0) {

            var tableData = []
            var i = 0
            tableData.length = response.data.total
            for (i; i < response.data.item.length; i++) {
              tableData[i] =
              {
                taskid: 1,
                fenceid: null,
              }

              tableData[i].taskid = response.data.item[i].taskId
              if (response.data.item[i].type == 1)
                tableData[i].type = '工务作业'
              if (response.data.item[i].type == 3)
                tableData[i].type = '巡道作业'
              if (response.data.item[i].type == 5)
                tableData[i].type = '其它作业'
              if (response.data.item[i].type == 4)
                tableData[i].type = '列检作业'
              if (response.data.item[i].type == 2)
                tableData[i].type = '电务作业'
              if (response.data.item[i].type == 6)
                tableData[i].type = '机务作业'
              if (response.data.item[i].type == 7)
                tableData[i].type = '调车作业'
              if (response.data.item[i].type == 8)
                tableData[i].type = '商检作业'
              if (response.data.item[i].state == 3)
                tableData[i].state = "startTask"
              else if (response.data.item[i].state == 5)
                tableData[i].state = "endTask"
              else tableData[i].state = "overTask"
              if (response.data.item[i].fenceIds.length != 0)
                tableData[i].fenceid = response.data.item[i].fenceIds[0]
              if (response.data.item[i].beginTime != undefined) {
                tableData[i].beginTime = new Date(response.data.item[i].beginTime)
                tableData[i].beginTime = getFormatDateTime(tableData[i].beginTime)
              }
              else tableData[i].beginTime = "---      "
              if (response.data.item[i].endTime != undefined) {
                tableData[i].endTime = new Date(response.data.item[i].endTime)
                tableData[i].endTime = getFormatDateTime(tableData[i].endTime)
              }
              else tableData[i].endTime = " ---"
              if (response.data.item[i].beginTime_plan != undefined) {
                tableData[i].beginTime_plan = new Date(response.data.item[i].beginTime_plan)
                tableData[i].beginTime_plan = getFormatDateTime(tableData[i].beginTime_plan)
              }
              else tableData[i].beginTime_plan = "---                "
              if (response.data.item[i].endTime_plan != undefined) {
                tableData[i].endTime_plan = new Date(response.data.item[i].endTime_plan)
                tableData[i].endTime_plan = getFormatDateTime(tableData[i].endTime_plan)
              }
              else tableData[i].endTime_plan = " ---"


            }
            this.tableData = tableData
            // this.twoData=tableData
            // {
            //   console.log(filters.select_state)
            //   if(filters.select_state.length>0)
            //   {
            //     for(var i=0;i<this.tableData.length;i++)
            //   {
            //     var this_select=0
            //     for(var j=0;j<filters.select_state.length;j++)
            //     if(this.tableData[i].state==filters.select_state[j])
            //     this_select=1
            //     if(this_select==1)
            //     this.newData.push(this.tableData[i])
            //   }
            //   this.twoData=this.newData
            //   }
            //   else this.twoData=this.tableData
            // }
            // if(this.twoData.length<(this.currentPage-1)*this.pagesize)
            // this.currentPage=(this.twoData.length-(this.twoData.length%this.pagesize))/this.pagesize+1

          }
          else this.requestState = true


        }).catch(error => {
          if (error.message.includes('timeout')) {
            this.requestState = true
          }
        });


      }




    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
      this.subSocketChannel()
    },
    handleSizeChange: function (size) {
      this.pagesize = size
      this.subSocketChannel()
    },
    checkfence_create(fenceid) {

      this.checkfenceid = fenceid
      this.openCheckFence_create = true
    },
    checkfence(fenceid, taskid) {


      this.checktaskid = taskid
      this.checkfenceid = fenceid
      this.openCheckFence = true
    },
    delectefence() {

      this.fenceid = null
    },
    getData() {
      getLineData().then((response) => {
        if (response.code == 0) {
          this.station_lists_1 = [{}, {}]

          this.station_lists_1[0] = {
            'value': 0,
            'label': '车站',
            'children': []
          }
          this.station_lists_1[1] = {
            'value': 1,
            'label': '区间',
            'children': []
          }
          this.station_lists_2[0] = {
            'value': 0,
            'label': '车站',
            'children': []
          }
          this.station_lists_2[1] = {
            'value': 0,
            'label': '区间',
            'children': []
          }
          this.station_lists_3[0] = {
            'value': 0,
            'label': '车站',
            'children': []
          }
          var i = 0
          for (var key in response.data) {
            this.station_lists_1[0].children[i] = {
              'value': 1,
              'label': 1,
              'children': []
            }
            this.station_lists_1[0].children[i].value = key
            this.station_lists_1[0].children[i].label = response.data[key].baseInfo.stationName
            var j = 0
            for (j; j < response.data[key].tracks.length; j++) {
              this.station_lists_1[0].children[i].children[j] = {
                'value': 1,
                'label': 1,
                'type': 'track',
                'stationNo': 1,
                'areaType': 1,
                'stationName': 1
              }
              this.station_lists_1[0].children[i].children[j].value = response.data[key].tracks[j].id
              this.station_lists_1[0].children[i].children[j].label = response.data[key].tracks[j].name
              this.station_lists_1[0].children[i].children[j].stationNo = response.data[key].baseInfo.stationNo   //2023.02.12临时修改
              this.station_lists_1[0].children[i].children[j].stationName = response.data[key].baseInfo.stationName  //2023.02.12临时修改
              //this.station_lists_1[0].children[i].children[j].stationNo=803
              //this.station_lists_1[0].children[i].children[j].stationName='日照石臼港区V场'
            }
            i++
          }
        }
        else this.requestState = true
      }).catch(error => {
        if (error.message.includes('timeout')) {
          this.requestState = true
        }
      });

      getSectionData().then((response) => {   //+10000用以区分站间和股道
        if (response.code == 0) {
          var i = 0
          for (var key in response.data) {
            this.station_lists_1[1].children[i] = {
              'value': 1,
              'label': 1,
              'stationNo1': '',
              'stationName1': '',
              'stationNo2': '',
              'stationName2': '',
            }
            this.station_lists_1[1].children[i].value = response.data[key].sectionId
            this.station_lists_1[1].children[i].label = response.data[key].stations[0].stationName + '——' + response.data[key].stations[1].stationName
            this.station_lists_1[1].children[i].stations = response.data[key].stations
            i++
          }
          this.resetoptions = 0
        }
        else this.requestState = true
      }).catch(error => {
        if (error.message.includes('timeout')) {
          this.requestState = true
        }
      });
    },

    getPreviewImgList(index, imgArr) {
      let arr = []
      let i = 0;
      for (i; i < imgArr.length; i++) {
        arr.push(imgArr[i + index])
        if (i + index >= imgArr.length - 1) {
          index = 0 - (i + 1);
        }
      }
      return arr;
    },

    viewpicture(taskid) {

      let that = this
      getImagePaths(taskid).then((response) => {
        if (response.code == 0) {
          that.picFileList[taskid] = []
          if (response.data == [])
            this.picture_length = false
          response.data.forEach((path) => {
            this.picture_length = true
            // var new_path='http://192.168.16.110:9527/pic'+path
            var new_path = 'http://' + window.location.host + '/pic' + path
            that.picFileList[taskid].push(new_path)
          })
          this.checkpicture = true
          this.checkpicture_taskid = taskid
        }
        else this.requestState = true
      }).catch(error => {
        if (error.message.includes('timeout')) {
          this.requestState = true
        }
      });
    },
    filterHandler(value, row, column) {
      const property = column['property'];
      return row[property] === value;
    },
    updateState(taskid, state) {

      putTaskOperate(taskid, state).then((response) => {
        if (response.code == 0)
          this.searchEvents2()
      }).catch(error => {
        if (error.message.includes('timeout')) {
          this.requestState = true
        }
      });
    },
    ClickCheck(taskid) {
      let that = this
      this.form_one = true
      this.form_two = true
      this.form_three = true
      this.checkUserDialog = true
      getTaskInfo(taskid).then((response) => {
        if (response.code == 0) {
          if (response.data.type == 1) {
            that.choosed = 'check_one'
            that.one_input_1 = response.data.workContent
            that.one_input_2 = response.data.comment
            that.ruleForm.date1 = response.data.beginTime_plan
            that.ruleForm.date2 = response.data.endTime_plan
            that.ruleForm.manager = []
            that.ruleForm.liaison = []
            that.ruleForm.safeman = []
            that.ruleForm.worker = []

            for (var i = 0; i < response.data.manager.length; i++) {
              that.ruleForm.manager[i] = []
              that.ruleForm.manager[i][0] = 0
              if (response.data.manager[i].type == 'user')
                that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
              else {
                that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                that.ruleForm.manager[i][0] = 1
                that.ruleForm.manager[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.liaison.length; i++) {
              that.ruleForm.liaison[i] = []
              that.ruleForm.liaison[i][0] = 0
              if (response.data.liaison[i].type == 'user')
                that.ruleForm.liaison[i][1] = ('US' + response.data.liaison[i].id)
              else {
                that.ruleForm.liaison[i][2] = ('DE' + response.data.liaison[i].id)
                that.ruleForm.liaison[i][0] = 1
                that.ruleForm.liaison[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.safeman.length; i++) {
              that.ruleForm.safeman[i] = []
              that.ruleForm.safeman[i][0] = 0
              if (response.data.safeman[i].type == 'user')
                that.ruleForm.safeman[i][1] = ('US' + response.data.safeman[i].id)
              else {
                that.ruleForm.safeman[i][2] = ('DE' + response.data.safeman[i].id)
                that.ruleForm.safeman[i][0] = 1
                that.ruleForm.safeman[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.worker.length; i++) {
              that.ruleForm.worker[i] = []
              that.ruleForm.worker[i][0] = 0
              if (response.data.worker[i].type == 'user')
                that.ruleForm.worker[i][1] = ('US' + response.data.worker[i].id)
              else if (response.data.worker[i].type == 'userGroup') {
                that.ruleForm.worker[i][1] = ('UG' + response.data.worker[i].id)
                that.ruleForm.worker[i][0] = 1
              }

              else if (response.data.worker[i].type == 'deviceGroup') {
                that.ruleForm.worker[i][1] = ('DG' + response.data.worker[i].id)
                that.ruleForm.worker[i][0] = 3
              }

              else {
                that.ruleForm.worker[i][2] = ('DE' + response.data.worker[i].id)
                that.ruleForm.worker[i][0] = 2
                that.ruleForm.worker[i][1] = 0
              }
            }
            if (response.data.workArea.type == 1)
              for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                {
                  that.ruleForm.area = []
                  that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                  that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                  that.ruleForm.area[0] = 0
                }

              }
            else if (response.data.workArea.type == 2) {
              that.ruleForm.area = []
              that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
              that.ruleForm.area[0] = 1
            }
            that.start_kilometer_1 = response.data.workArea.areaKM.start.kilo
            that.start_meter_1 = response.data.workArea.areaKM.start.meter
            that.end_kilometer_1 = response.data.workArea.areaKM.end.kilo
            that.end_meter_1 = response.data.workArea.areaKM.end.meter
            that.location_supplied_1 = response.data.workArea.areaComment

          }
          if (response.data.type == 2) {
            that.choosed = 'check_four'
            that.one_input_1 = response.data.workContent
            that.one_input_2 = response.data.comment
            that.ruleForm.date1 = response.data.beginTime_plan
            that.ruleForm.date2 = response.data.endTime_plan
            that.ruleForm.manager = []
            that.ruleForm.liaison = []
            that.ruleForm.safeman = []
            that.ruleForm.worker = []

            for (var i = 0; i < response.data.manager.length; i++) {
              that.ruleForm.manager[i] = []
              that.ruleForm.manager[i][0] = 0
              if (response.data.manager[i].type == 'user')
                that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
              else {
                that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                that.ruleForm.manager[i][0] = 1
                that.ruleForm.manager[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.liaison.length; i++) {
              that.ruleForm.liaison[i] = []
              that.ruleForm.liaison[i][0] = 0
              if (response.data.liaison[i].type == 'user')
                that.ruleForm.liaison[i][1] = ('US' + response.data.liaison[i].id)
              else {
                that.ruleForm.liaison[i][2] = ('DE' + response.data.liaison[i].id)
                that.ruleForm.liaison[i][0] = 1
                that.ruleForm.liaison[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.safeman.length; i++) {
              that.ruleForm.safeman[i] = []
              that.ruleForm.safeman[i][0] = 0
              if (response.data.safeman[i].type == 'user')
                that.ruleForm.safeman[i][1] = ('US' + response.data.safeman[i].id)
              else {
                that.ruleForm.safeman[i][2] = ('DE' + response.data.safeman[i].id)
                that.ruleForm.safeman[i][0] = 1
                that.ruleForm.safeman[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.worker.length; i++) {
              that.ruleForm.worker[i] = []
              that.ruleForm.worker[i][0] = 0
              if (response.data.worker[i].type == 'user')
                that.ruleForm.worker[i][1] = ('US' + response.data.worker[i].id)
              else if (response.data.worker[i].type == 'userGroup') {
                that.ruleForm.worker[i][1] = ('UG' + response.data.worker[i].id)
                that.ruleForm.worker[i][0] = 1
              }

              else if (response.data.worker[i].type == 'deviceGroup') {
                that.ruleForm.worker[i][1] = ('DG' + response.data.worker[i].id)
                that.ruleForm.worker[i][0] = 3
              }

              else {
                that.ruleForm.worker[i][2] = ('DE' + response.data.worker[i].id)
                that.ruleForm.worker[i][0] = 2
                that.ruleForm.worker[i][1] = 0
              }
            }
            if (response.data.workArea.type == 1)
              for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                {
                  that.ruleForm.area = []
                  that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                  that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                  that.ruleForm.area[0] = 0
                }

              }
            else if (response.data.workArea.type == 2) {
              that.ruleForm.area = []
              that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
              that.ruleForm.area[0] = 1
            }
            that.start_kilometer_1 = response.data.workArea.areaKM.start.kilo
            that.start_meter_1 = response.data.workArea.areaKM.start.meter
            that.end_kilometer_1 = response.data.workArea.areaKM.end.kilo
            that.end_meter_1 = response.data.workArea.areaKM.end.meter
            that.location_supplied_1 = response.data.workArea.areaComment

          }
          if (response.data.type == 3) {
            that.choosed = 'check_two'
            that.two_input_1 = response.data.workContent
            that.two_input_2 = response.data.comment
            that.ruleForm.date1 = response.data.beginTime_plan
            that.ruleForm.date2 = response.data.endTime_plan
            that.ruleForm.manager = []
            that.ruleForm.petrolman = []
            for (var i = 0; i < response.data.manager.length; i++) {
              that.ruleForm.manager[i] = []
              that.ruleForm.manager[i][0] = 0
              if (response.data.manager[i].type == 'user')
                that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
              else {
                that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                that.ruleForm.manager[i][0] = 1
                that.ruleForm.manager[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.petrolman.length; i++) {
              that.ruleForm.petrolman[i] = []
              that.ruleForm.petrolman[i][0] = 0
              if (response.data.petrolman[i].type == 'user')
                that.ruleForm.petrolman[i][1] = ('US' + response.data.petrolman[i].id)
              else {
                that.ruleForm.petrolman[i][2] = ('DE' + response.data.petrolman[i].id)
                that.ruleForm.petrolman[i][0] = 1
                that.ruleForm.petrolman[i][1] = 0
              }
            }
            that.location_supplied_2 = response.data.workArea.areaComment
          }
          if (response.data.type == 4) {
            that.location_supplied_3 = response.data.workArea.areaComment
            that.choosed = 'check_three'
            that.three_input_1 = response.data.workContent
            that.three_input_2 = response.data.comment
            that.ruleForm.date1 = response.data.beginTime_plan
            that.ruleForm.date2 = response.data.endTime_plan
            that.ruleForm.manager = []
            that.ruleForm.trainChecker = []
            for (var i = 0; i < response.data.manager.length; i++) {
              that.ruleForm.manager[i] = []
              that.ruleForm.manager[i][0] = 0
              if (response.data.manager[i].type == 'user')
                that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
              else {
                that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                that.ruleForm.manager[i][0] = 1
                that.ruleForm.manager[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.trainChecker.length; i++) {
              that.ruleForm.trainChecker[i] = []
              that.ruleForm.trainChecker[i][0] = 0
              if (response.data.trainChecker[i].type == 'user')
                that.ruleForm.trainChecker[i][1] = ('US' + response.data.trainChecker[i].id)
              else {
                that.ruleForm.trainChecker[i][2] = ('DE' + response.data.trainChecker[i].id)
                that.ruleForm.trainChecker[i][0] = 1
                that.ruleForm.trainChecker[i][1] = 0
              }
            }
            if (response.data.workArea.type == 1)
              for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                {
                  that.ruleForm.area = []
                  that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                  that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                  that.ruleForm.area[0] = 0
                }

              }
            else if (response.data.workArea.type == 2) {
              that.ruleForm.area = []
              that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
              that.ruleForm.area[0] = 1
            }
          }
          if (response.data.type == 5) {
            that.choosed = 'check_eight'
            that.two_input_1 = response.data.workContent
            that.two_input_2 = response.data.comment
            that.ruleForm.date1 = response.data.beginTime_plan
            that.ruleForm.date2 = response.data.endTime_plan
            that.ruleForm.manager = []
            that.ruleForm.petrolman = []
            for (var i = 0; i < response.data.manager.length; i++) {
              that.ruleForm.manager[i] = []
              that.ruleForm.manager[i][0] = 0
              if (response.data.manager[i].type == 'user')
                that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
              else {
                that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                that.ruleForm.manager[i][0] = 1
                that.ruleForm.manager[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.petrolman.length; i++) {
              that.ruleForm.petrolman[i] = []
              that.ruleForm.petrolman[i][0] = 0
              if (response.data.petrolman[i].type == 'user')
                that.ruleForm.petrolman[i][1] = ('US' + response.data.petrolman[i].id)
              else {
                that.ruleForm.petrolman[i][2] = ('DE' + response.data.petrolman[i].id)
                that.ruleForm.petrolman[i][0] = 1
                that.ruleForm.petrolman[i][1] = 0
              }
            }
            that.location_supplied_2 = response.data.workArea.areaComment
          }
          if (response.data.type == 6) {
            that.location_supplied_3 = response.data.workArea.areaComment
            that.choosed = 'check_six'
            that.three_input_1 = response.data.workContent
            that.three_input_2 = response.data.comment
            that.ruleForm.date1 = response.data.beginTime_plan
            that.ruleForm.date2 = response.data.endTime_plan
            that.ruleForm.manager = []
            that.ruleForm.trainChecker = []
            for (var i = 0; i < response.data.manager.length; i++) {
              that.ruleForm.manager[i] = []
              that.ruleForm.manager[i][0] = 0
              if (response.data.manager[i].type == 'user')
                that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
              else {
                that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                that.ruleForm.manager[i][0] = 1
                that.ruleForm.manager[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.trainChecker.length; i++) {
              that.ruleForm.trainChecker[i] = []
              that.ruleForm.trainChecker[i][0] = 0
              if (response.data.trainChecker[i].type == 'user')
                that.ruleForm.trainChecker[i][1] = ('US' + response.data.trainChecker[i].id)
              else {
                that.ruleForm.trainChecker[i][2] = ('DE' + response.data.trainChecker[i].id)
                that.ruleForm.trainChecker[i][0] = 1
                that.ruleForm.trainChecker[i][1] = 0
              }
            }
            if (response.data.workArea.type == 1)
              for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                {
                  that.ruleForm.area = []
                  that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                  that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                  that.ruleForm.area[0] = 0
                }

              }
            else if (response.data.workArea.type == 2) {
              that.ruleForm.area = []
              that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
              that.ruleForm.area[0] = 1
            }
          }
          if (response.data.type == 7) {
            that.location_supplied_3 = response.data.workArea.areaComment
            that.choosed = 'check_seven'
            that.three_input_1 = response.data.workContent
            that.three_input_2 = response.data.comment
            that.ruleForm.date1 = response.data.beginTime_plan
            that.ruleForm.date2 = response.data.endTime_plan
            that.ruleForm.manager = []
            that.ruleForm.trainChecker = []
            for (var i = 0; i < response.data.manager.length; i++) {
              that.ruleForm.manager[i] = []
              that.ruleForm.manager[i][0] = 0
              if (response.data.manager[i].type == 'user')
                that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
              else {
                that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                that.ruleForm.manager[i][0] = 1
                that.ruleForm.manager[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.trainChecker.length; i++) {
              that.ruleForm.trainChecker[i] = []
              that.ruleForm.trainChecker[i][0] = 0
              if (response.data.trainChecker[i].type == 'user')
                that.ruleForm.trainChecker[i][1] = ('US' + response.data.trainChecker[i].id)
              else {
                that.ruleForm.trainChecker[i][2] = ('DE' + response.data.trainChecker[i].id)
                that.ruleForm.trainChecker[i][0] = 1
                that.ruleForm.trainChecker[i][1] = 0
              }
            }
            if (response.data.workArea.type == 1)
              for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                {
                  that.ruleForm.area = []
                  that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                  that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                  that.ruleForm.area[0] = 0
                }

              }
            else if (response.data.workArea.type == 2) {
              that.ruleForm.area = []
              that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
              that.ruleForm.area[0] = 1
            }
          }
          if (response.data.type == 8) {
            that.location_supplied_3 = response.data.workArea.areaComment
            that.choosed = 'check_five'
            that.three_input_1 = response.data.workContent
            that.three_input_2 = response.data.comment
            that.ruleForm.date1 = response.data.beginTime_plan
            that.ruleForm.date2 = response.data.endTime_plan
            that.ruleForm.manager = []
            that.ruleForm.trainChecker = []
            for (var i = 0; i < response.data.manager.length; i++) {
              that.ruleForm.manager[i] = []
              that.ruleForm.manager[i][0] = 0
              if (response.data.manager[i].type == 'user')
                that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
              else {
                that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                that.ruleForm.manager[i][0] = 1
                that.ruleForm.manager[i][1] = 0
              }
            }
            for (var i = 0; i < response.data.trainChecker.length; i++) {
              that.ruleForm.trainChecker[i] = []
              that.ruleForm.trainChecker[i][0] = 0
              if (response.data.trainChecker[i].type == 'user')
                that.ruleForm.trainChecker[i][1] = ('US' + response.data.trainChecker[i].id)
              else {
                that.ruleForm.trainChecker[i][2] = ('DE' + response.data.trainChecker[i].id)
                that.ruleForm.trainChecker[i][0] = 1
                that.ruleForm.trainChecker[i][1] = 0
              }
            }
            if (response.data.workArea.type == 1)
              for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                {
                  that.ruleForm.area = []
                  that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                  that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                  that.ruleForm.area[0] = 0
                }

              }
            else if (response.data.workArea.type == 2) {
              that.ruleForm.area = []
              that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
              that.ruleForm.area[0] = 1
            }
          }
        }
        else this.requestState = true

      }).catch(error => {
        if (error.message.includes('timeout')) {
          this.requestState = true
        }
      });

    },
    ClickEdit(taskid, state) {
      let that = this
      this.selectfence_way = ''
      this.openFenceType = false
      this.openSelectTrack = false
      this.openSelectFence = false
      this.updateUserDialog = true
      this.edit_taskid = taskid
      if (state == 'startTask')
        getTaskInfo(taskid).then((response) => {
          if (response.code == 0) {
            if (response.data.type == 1) {

              that.choosed = 'update_one'
              that.one_input_1 = response.data.workContent
              that.one_input_2 = response.data.comment
              for (var key in response.data.fences)
                that.fenceid = key
              that.ruleForm.date1 = response.data.beginTime_plan
              that.ruleForm.date2 = response.data.endTime_plan
              that.ruleForm.manager = []
              that.ruleForm.liaison = []
              that.ruleForm.safeman = []
              that.ruleForm.worker = []
              that.ruleForm.area = []
              for (var i = 0; i < response.data.manager.length; i++) {
                that.ruleForm.manager[i] = []
                that.ruleForm.manager[i][0] = 0
                if (response.data.manager[i].type == 'user')
                  that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
                else {
                  that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                  that.ruleForm.manager[i][0] = 1
                  that.ruleForm.manager[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.liaison.length; i++) {
                that.ruleForm.liaison[i] = []
                that.ruleForm.liaison[i][0] = 0
                if (response.data.liaison[i].type == 'user')
                  that.ruleForm.liaison[i][1] = ('US' + response.data.liaison[i].id)
                else {
                  that.ruleForm.liaison[i][2] = ('DE' + response.data.liaison[i].id)
                  that.ruleForm.liaison[i][0] = 1
                  that.ruleForm.liaison[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.safeman.length; i++) {
                that.ruleForm.safeman[i] = []
                that.ruleForm.safeman[i][0] = 0
                if (response.data.safeman[i].type == 'user')
                  that.ruleForm.safeman[i][1] = ('US' + response.data.safeman[i].id)
                else {
                  that.ruleForm.safeman[i][2] = ('DE' + response.data.safeman[i].id)
                  that.ruleForm.safeman[i][0] = 1
                  that.ruleForm.safeman[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.worker.length; i++) {
                that.ruleForm.worker[i] = []
                that.ruleForm.worker[i][0] = 0
                if (response.data.worker[i].type == 'user')
                  that.ruleForm.worker[i][1] = ('US' + response.data.worker[i].id)
                else if (response.data.worker[i].type == 'userGroup') {
                  that.ruleForm.worker[i][1] = ('UG' + response.data.worker[i].id)
                  that.ruleForm.worker[i][0] = 1
                }
                else if (response.data.worker[i].type == 'deviceGroup') {
                  that.ruleForm.worker[i][1] = ('DG' + response.data.worker[i].id)
                  that.ruleForm.worker[i][0] = 3
                }

                else {
                  that.ruleForm.worker[i][2] = ('DE' + response.data.worker[i].id)
                  that.ruleForm.worker[i][0] = 2
                  that.ruleForm.worker[i][1] = 0
                }
              }

              if (response.data.workArea.type == 1)
                for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                  {
                    that.ruleForm.area = []
                    that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                    that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                    that.ruleForm.area[0] = 0
                  }

                }
              else if (response.data.workArea.type == 2) {
                that.ruleForm.area = []
                that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
                that.ruleForm.area[0] = 1
              }
              that.start_kilometer_1 = response.data.workArea.areaKM.start.kilo
              that.start_meter_1 = response.data.workArea.areaKM.start.meter
              that.end_kilometer_1 = response.data.workArea.areaKM.end.kilo
              that.end_meter_1 = response.data.workArea.areaKM.end.meter
              that.location_supplied_1 = response.data.workArea.areaComment

            }
            if (response.data.type == 2) {

              that.choosed = 'update_four'
              that.one_input_1 = response.data.workContent
              that.one_input_2 = response.data.comment
              for (var key in response.data.fences)
                that.fenceid = key
              that.ruleForm.date1 = response.data.beginTime_plan
              that.ruleForm.date2 = response.data.endTime_plan
              that.ruleForm.manager = []
              that.ruleForm.liaison = []
              that.ruleForm.safeman = []
              that.ruleForm.worker = []
              that.ruleForm.area = []
              for (var i = 0; i < response.data.manager.length; i++) {
                that.ruleForm.manager[i] = []
                that.ruleForm.manager[i][0] = 0
                if (response.data.manager[i].type == 'user')
                  that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
                else {
                  that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                  that.ruleForm.manager[i][0] = 1
                  that.ruleForm.manager[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.liaison.length; i++) {
                that.ruleForm.liaison[i] = []
                that.ruleForm.liaison[i][0] = 0
                if (response.data.liaison[i].type == 'user')
                  that.ruleForm.liaison[i][1] = ('US' + response.data.liaison[i].id)
                else {
                  that.ruleForm.liaison[i][2] = ('DE' + response.data.liaison[i].id)
                  that.ruleForm.liaison[i][0] = 1
                  that.ruleForm.liaison[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.safeman.length; i++) {
                that.ruleForm.safeman[i] = []
                that.ruleForm.safeman[i][0] = 0
                if (response.data.safeman[i].type == 'user')
                  that.ruleForm.safeman[i][1] = ('US' + response.data.safeman[i].id)
                else {
                  that.ruleForm.safeman[i][2] = ('DE' + response.data.safeman[i].id)
                  that.ruleForm.safeman[i][0] = 1
                  that.ruleForm.safeman[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.worker.length; i++) {
                that.ruleForm.worker[i] = []
                that.ruleForm.worker[i][0] = 0
                if (response.data.worker[i].type == 'user')
                  that.ruleForm.worker[i][1] = ('US' + response.data.worker[i].id)
                else if (response.data.worker[i].type == 'userGroup') {
                  that.ruleForm.worker[i][1] = ('UG' + response.data.worker[i].id)
                  that.ruleForm.worker[i][0] = 1
                }
                else if (response.data.worker[i].type == 'deviceGroup') {
                  that.ruleForm.worker[i][1] = ('DG' + response.data.worker[i].id)
                  that.ruleForm.worker[i][0] = 3
                }

                else {
                  that.ruleForm.worker[i][2] = ('DE' + response.data.worker[i].id)
                  that.ruleForm.worker[i][0] = 2
                  that.ruleForm.worker[i][1] = 0
                }
              }

              if (response.data.workArea.type == 1)
                for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                  {
                    that.ruleForm.area = []
                    that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                    that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                    that.ruleForm.area[0] = 0
                  }

                }
              else if (response.data.workArea.type == 2) {
                that.ruleForm.area = []
                that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
                that.ruleForm.area[0] = 1
              }
              that.start_kilometer_1 = response.data.workArea.areaKM.start.kilo
              that.start_meter_1 = response.data.workArea.areaKM.start.meter
              that.end_kilometer_1 = response.data.workArea.areaKM.end.kilo
              that.end_meter_1 = response.data.workArea.areaKM.end.meter
              that.location_supplied_1 = response.data.workArea.areaComment

            }
            if (response.data.type == 3) {
              that.choosed = 'update_two'
              that.two_input_1 = response.data.workContent
              that.two_input_2 = response.data.comment

              that.ruleForm.date1 = response.data.beginTime_plan
              that.ruleForm.date2 = response.data.endTime_plan
              that.ruleForm.manager = []
              that.ruleForm.petrolman = []
              for (var i = 0; i < response.data.manager.length; i++) {
                that.ruleForm.manager[i] = []
                that.ruleForm.manager[i][0] = 0
                if (response.data.manager[i].type == 'user')
                  that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
                else {
                  that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                  that.ruleForm.manager[i][0] = 1
                  that.ruleForm.manager[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.petrolman.length; i++) {
                that.ruleForm.petrolman[i] = []
                that.ruleForm.petrolman[i][0] = 0
                if (response.data.petrolman[i].type == 'user')
                  that.ruleForm.petrolman[i][1] = ('US' + response.data.petrolman[i].id)
                else {
                  that.ruleForm.petrolman[i][2] = ('DE' + response.data.petrolman[i].id)
                  that.ruleForm.petrolman[i][0] = 1
                  that.ruleForm.petrolman[i][1] = 0
                }
              }
              that.location_supplied_2 = response.data.workArea.areaComment
            }
            if (response.data.type == 4) {
              that.location_supplied_3 = response.data.workArea.areaComment
              that.choosed = 'update_three'
              that.autoCreateFence = false
              that.three_input_1 = response.data.workContent
              that.three_input_2 = response.data.comment
              that.ruleForm.area = []
              for (var key in response.data.fences)
                that.fenceid_traincheck = key
              that.ruleForm.date1 = response.data.beginTime_plan
              that.ruleForm.date2 = response.data.endTime_plan
              that.ruleForm.manager = []
              that.ruleForm.trainChecker = []
              for (var i = 0; i < response.data.manager.length; i++) {
                that.ruleForm.manager[i] = []
                that.ruleForm.manager[i][0] = 0
                if (response.data.manager[i].type == 'user')
                  that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
                else {
                  that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                  that.ruleForm.manager[i][0] = 1
                  that.ruleForm.manager[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.trainChecker.length; i++) {
                that.ruleForm.trainChecker[i] = []
                that.ruleForm.trainChecker[i][0] = 0
                if (response.data.trainChecker[i].type == 'user')
                  that.ruleForm.trainChecker[i][1] = ('US' + response.data.trainChecker[i].id)
                else {
                  that.ruleForm.trainChecker[i][2] = ('DE' + response.data.trainChecker[i].id)
                  that.ruleForm.trainChecker[i][0] = 1
                  that.ruleForm.trainChecker[i][1] = 0
                }
              }
              if (response.data.workArea.type == 1)
                for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                  {
                    that.ruleForm.area = []
                    that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                    that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                    that.ruleForm.area[0] = 0
                  }

                }
              else if (response.data.workArea.type == 2) {
                that.ruleForm.area = []
                that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
                that.ruleForm.area[0] = 1
              }
            }
            if (response.data.type == 5) {
              that.choosed = 'update_eight'
              that.two_input_1 = response.data.workContent
              that.two_input_2 = response.data.comment

              that.ruleForm.date1 = response.data.beginTime_plan
              that.ruleForm.date2 = response.data.endTime_plan
              that.ruleForm.manager = []
              that.ruleForm.petrolman = []
              for (var i = 0; i < response.data.manager.length; i++) {
                that.ruleForm.manager[i] = []
                that.ruleForm.manager[i][0] = 0
                if (response.data.manager[i].type == 'user')
                  that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
                else {
                  that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                  that.ruleForm.manager[i][0] = 1
                  that.ruleForm.manager[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.petrolman.length; i++) {
                that.ruleForm.petrolman[i] = []
                that.ruleForm.petrolman[i][0] = 0
                if (response.data.petrolman[i].type == 'user')
                  that.ruleForm.petrolman[i][1] = ('US' + response.data.petrolman[i].id)
                else {
                  that.ruleForm.petrolman[i][2] = ('DE' + response.data.petrolman[i].id)
                  that.ruleForm.petrolman[i][0] = 1
                  that.ruleForm.petrolman[i][1] = 0
                }
              }
              that.location_supplied_2 = response.data.workArea.areaComment
            }
            if (response.data.type == 6) {
              that.location_supplied_3 = response.data.workArea.areaComment
              that.choosed = 'update_six'
              that.three_input_1 = response.data.workContent
              that.three_input_2 = response.data.comment
              that.ruleForm.area = []
              that.ruleForm.date1 = response.data.beginTime_plan
              that.ruleForm.date2 = response.data.endTime_plan
              that.ruleForm.manager = []
              that.ruleForm.trainChecker = []
              for (var i = 0; i < response.data.manager.length; i++) {
                that.ruleForm.manager[i] = []
                that.ruleForm.manager[i][0] = 0
                if (response.data.manager[i].type == 'user')
                  that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
                else {
                  that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                  that.ruleForm.manager[i][0] = 1
                  that.ruleForm.manager[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.trainChecker.length; i++) {
                that.ruleForm.trainChecker[i] = []
                that.ruleForm.trainChecker[i][0] = 0
                if (response.data.trainChecker[i].type == 'user')
                  that.ruleForm.trainChecker[i][1] = ('US' + response.data.trainChecker[i].id)
                else {
                  that.ruleForm.trainChecker[i][2] = ('DE' + response.data.trainChecker[i].id)
                  that.ruleForm.trainChecker[i][0] = 1
                  that.ruleForm.trainChecker[i][1] = 0
                }
              }
              if (response.data.workArea.type == 1)
                for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                  {
                    that.ruleForm.area = []
                    that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                    that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                    that.ruleForm.area[0] = 0
                  }

                }
              else if (response.data.workArea.type == 2) {
                that.ruleForm.area = []
                that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
                that.ruleForm.area[0] = 1
              }
            }
            if (response.data.type == 7) {
              that.location_supplied_3 = response.data.workArea.areaComment
              that.choosed = 'update_seven'
              that.three_input_1 = response.data.workContent
              that.three_input_2 = response.data.comment
              that.ruleForm.area = []
              that.ruleForm.date1 = response.data.beginTime_plan
              that.ruleForm.date2 = response.data.endTime_plan
              that.ruleForm.manager = []
              that.ruleForm.trainChecker = []
              for (var i = 0; i < response.data.manager.length; i++) {
                that.ruleForm.manager[i] = []
                that.ruleForm.manager[i][0] = 0
                if (response.data.manager[i].type == 'user')
                  that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
                else {
                  that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                  that.ruleForm.manager[i][0] = 1
                  that.ruleForm.manager[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.trainChecker.length; i++) {
                that.ruleForm.trainChecker[i] = []
                that.ruleForm.trainChecker[i][0] = 0
                if (response.data.trainChecker[i].type == 'user')
                  that.ruleForm.trainChecker[i][1] = ('US' + response.data.trainChecker[i].id)
                else {
                  that.ruleForm.trainChecker[i][2] = ('DE' + response.data.trainChecker[i].id)
                  that.ruleForm.trainChecker[i][0] = 1
                  that.ruleForm.trainChecker[i][1] = 0
                }
              }
              if (response.data.workArea.type == 1)
                for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                  {
                    that.ruleForm.area = []
                    that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                    that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                    that.ruleForm.area[0] = 0
                  }

                }
              else if (response.data.workArea.type == 2) {
                that.ruleForm.area = []
                that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
                that.ruleForm.area[0] = 1
              }
            }
            if (response.data.type == 8) {
              that.location_supplied_3 = response.data.workArea.areaComment
              that.choosed = 'update_five'
              that.autoCreateFence = false
              that.three_input_1 = response.data.workContent
              that.three_input_2 = response.data.comment
              that.ruleForm.area = []
              for (var key in response.data.fences)
                that.fenceid_traincheck = key
              that.ruleForm.date1 = response.data.beginTime_plan
              that.ruleForm.date2 = response.data.endTime_plan
              that.ruleForm.manager = []
              that.ruleForm.trainChecker = []
              for (var i = 0; i < response.data.manager.length; i++) {
                that.ruleForm.manager[i] = []
                that.ruleForm.manager[i][0] = 0
                if (response.data.manager[i].type == 'user')
                  that.ruleForm.manager[i][1] = ('US' + response.data.manager[i].id)
                else {
                  that.ruleForm.manager[i][2] = ('DE' + response.data.manager[i].id)
                  that.ruleForm.manager[i][0] = 1
                  that.ruleForm.manager[i][1] = 0
                }
              }
              for (var i = 0; i < response.data.trainChecker.length; i++) {
                that.ruleForm.trainChecker[i] = []
                that.ruleForm.trainChecker[i][0] = 0
                if (response.data.trainChecker[i].type == 'user')
                  that.ruleForm.trainChecker[i][1] = ('US' + response.data.trainChecker[i].id)
                else {
                  that.ruleForm.trainChecker[i][2] = ('DE' + response.data.trainChecker[i].id)
                  that.ruleForm.trainChecker[i][0] = 1
                  that.ruleForm.trainChecker[i][1] = 0
                }
              }
              if (response.data.workArea.type == 1)
                for (var i = 0; i < response.data.workArea.area[0].places.length; i++) {

                  {
                    that.ruleForm.area = []
                    that.ruleForm.area[2] = response.data.workArea.area[0].places[0].id
                    that.ruleForm.area[1] = String(response.data.workArea.area[0].stationNo)
                    that.ruleForm.area[0] = 0
                  }

                }
              else if (response.data.workArea.type == 2) {
                that.ruleForm.area = []
                that.ruleForm.area[1] = response.data.workArea.area[0].sectionId
                that.ruleForm.area[0] = 1
              }
            }
          }
          else this.requestState = true

        }).catch(error => {
          if (error.message.includes('timeout')) {
            this.requestState = true
          }
        });
      else {
        this.cannotupdatetask = true
        return false
      }
    },

    ClickDelete(taskid, state) {
      {
        this.$confirm('此操作将永久删除任务, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

          this.delete_taskid = taskid
          if (state == 'startTask')
            deleteTaskInfo(taskid).then(response => {
              if (response.code == 0) {
                this.deletetasksuccess = true
                this.searchEvents2()
              }

              else this.deletetaskfailed = true
            })
          else this.cannotdeletetask = true
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        }).catch(error => {
          if (error.message.includes('timeout')) {
            this.requestState = true
          }
        });
      }

    },


    resData() {
      this.form_one = false;
      this.form_two = false;
      this.form_three = false;
      this.createUserDialog = true;
      this.choosed = 'select'
      this.selectfence_way = ''
      this.openFenceType = false
      this.openSelectTrack = false
      this.openSelectFence = false
      this.ruleForm.date1 = ''
      this.ruleForm.date2 = ''
      this.ruleForm.date1 = ''
      this.ruleForm.date2 = ''
      this.ruleForm.date1 = ''
      this.ruleForm.date2 = ''
      this.ruleForm = {
        name: '',
        region: '',
        area: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: '',
        manager: '',
        safeman: '',
        liaison: '',
        worker: '',
        petrolman: '',
        trainChecker: '',
      }
      this.ruleForm.area = ''
      this.station_list2 = ''
      this.ruleForm.area = ''
      this.start_kilometer_1 = ''
      this.start_meter_1 = ''
      this.end_kilometer_1 = ''
      this.end_meter_1 = ''
      this.location_supplied_1 = ''
      this.location_supplied_2 = ''
      this.location_supplied_3 = ''
      this.one_input_1 = ''
      this.fenceid = ''
      this.fenceid_traincheck = ''
      this.ruleForm.manager = ''
      this.ruleForm.liaison = ''
      this.ruleForm.safeman = ''
      this.ruleForm.worker = ''
      this.ruleForm.manager = ''
      this.ruleForm.petrolman = ''
      this.person_lists3_2 = ''
      this.person_lists4_2 = ''
      this.ruleForm.manager = ''
      this.ruleForm.trainChecker = ''
      this.person_lists3_3 = ''
      this.person_lists4_3 = ''
      this.one_input_2 = ''
      this.two_input_1 = ''
      this.two_input_2 = ''
      this.three_input_1 = ''
      this.three_input_2 = ''

    },
    createTask3() {
      var tasktype = 4
      if (this.choosed == 'three')
        tasktype = 4
      else tasktype = 8
      this.autoCreateFenceDialog = false
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.createUserDialog = false
          var taskinfo = {
            type: tasktype,
            state: 3,
            workArea: {
              type: 1,
              area: [
                {
                  places: [
                    {
                      id: '',
                      name: '',
                      type: ''
                    }
                  ],
                  stationNo: '',
                  stationName: ''
                }
              ],
              areaComment: '',
            },

            creater: {
              userId: null, deviceInfo: {
                "type": "PC",
                "id": null,
              }
            },
            beginTime_plan: getFormatDateTime(this.ruleForm.date1),
            endTime_plan: getFormatDateTime(this.ruleForm.date2),
            manager: [],
            trainChecker: [],
            fenceIds: [this.fenceid_traincheck],
            workContent: this.three_input_1,
            comment: this.three_input_2
          }
          if (!this.fenceid_traincheck)
            taskinfo.fenceIds = []
          if (this.ruleForm.area[0] == 0) {

            {
              for (var q = 0; q < this.station_lists_1[0].children.length; q++)
                if (this.station_lists_1[0].children[q].value == (this.ruleForm.area[1]))
                  var the_state = q

              for (var j = 0; j < this.station_lists_1[0].children[the_state].children.length; j++) {
                if (this.station_lists_1[0].children[the_state].children[j].value == (this.ruleForm.area[2])) {
                  taskinfo.workArea.type = this.station_lists_1[0].children[the_state].children[j].areaType

                  taskinfo.workArea.area[0].stationNo = this.station_lists_1[0].children[the_state].children[j].stationNo
                  taskinfo.workArea.area[0].stationName = this.station_lists_1[0].children[the_state].children[j].stationName
                  taskinfo.workArea.area[0].places[0].id = this.station_lists_1[0].children[the_state].children[j].value
                  taskinfo.workArea.area[0].places[0].name = this.station_lists_1[0].children[the_state].children[j].label
                  taskinfo.workArea.area[0].places[0].type = this.station_lists_1[0].children[the_state].children[j].type
                }
              }
            }
          }
          taskinfo.workArea.areaComment = this.location_supplied_3
          this.ruleForm.manager.forEach((item) => {

            if (item[item.length - 1].match('US'))
              taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
            else if (item[item.length - 1].match('UG'))
              taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
            else if (item[item.length - 1].match('DG'))
              taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
            else taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
          })
          this.ruleForm.trainChecker.forEach((item) => {

            if (item[item.length - 1].match('US'))
              taskinfo.trainChecker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
            else if (item[item.length - 1].match('UG'))
              taskinfo.trainChecker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
            else if (item[item.length - 1].match('DG'))
              taskinfo.trainChecker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
            else taskinfo.trainChecker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
          })
          postTaskInfo(taskinfo).then((response) => {
            if (response.code == 0) {
              this.searchEvents2()
              this.createtasksuccess = true
            }
            else this.createtaskfailed = true
          }).catch(error => {
            if (error.message.includes('timeout')) {
              this.requestState = true
            }
          });
        }
        else {
          console.log('error submit!!');
          return false;
        }
      })

    },
    createTask2() {
      var tasktype = 4
      if (this.choosed == 'two')
        tasktype = 3
      else tasktype = 5
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.createUserDialog = false
          var taskinfo = {
            type: tasktype,
            state: 3,
            workArea: {
              type: 0,
              area: [
                {
                  places: [
                    {
                      id: '',
                      name: '',
                      type: ''
                    }
                  ],
                  stationNo: '',
                  stationName: ''
                }
              ],
              areaComment: '',
            },

            creater: {
              userId: null, deviceInfo: {
                "type": "PC",
                "id": null,
              }
            },
            beginTime_plan: getFormatDateTime(this.ruleForm.date1),
            endTime_plan: getFormatDateTime(this.ruleForm.date2),
            manager: [],
            petrolman: [],
            workContent: this.two_input_1,
            comment: this.two_input_2
          }
          // if(this.station_list2[0][0]==0)
          // {
          //   {
          //     for(var q=0;q<this.station_lists_1[0].children.length;q++)
          //     if(this.station_lists_1[0].children[q].value==(this.station_list2[0][1]))
          //     var the_state=q
          //     console.log(this.station_lists_1)
          //     for(var j=0;j<this.station_lists_1[0].children[the_state].children.length;j++)
          //     {
          //       if(this.station_lists_1[0].children[the_state].children[j].value==(this.station_list2[0][2]))
          //       {
          //         taskinfo.workArea.type=this.station_lists_1[0].children[the_state].children[j].areaType
          //         taskinfo.workArea.area[0].stationNo=this.station_lists_1[0].children[the_state].children[j].stationNo
          //         taskinfo.workArea.area[0].stationName=this.station_lists_1[0].children[the_state].children[j].stationName
          //         taskinfo.workArea.area[0].places[0].id=this.station_lists_1[0].children[the_state].children[j].value
          //         taskinfo.workArea.area[0].places[0].name=this.station_lists_1[0].children[the_state].children[j].label
          //         taskinfo.workArea.area[0].places[0].type=this.station_lists_1[0].children[the_state].children[j].type
          //       }
          //     }
          //   }
          // }
          taskinfo.workArea.areaComment = this.location_supplied_2
          this.ruleForm.manager.forEach((item) => {

            if (item[item.length - 1].match('US'))
              taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
            else if (item[item.length - 1].match('UG'))
              taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
            else if (item[item.length - 1].match('DG'))
              taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
            else taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
          })
          this.ruleForm.petrolman.forEach((item) => {

            if (item[item.length - 1].match('US'))
              taskinfo.petrolman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
            else if (item[item.length - 1].match('UG'))
              taskinfo.petrolman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
            else if (item[item.length - 1].match('DG'))
              taskinfo.petrolman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
            else taskinfo.petrolman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
          })
          postTaskInfo(taskinfo).then((response) => {
            if (response.code == 0) {
              this.searchEvents2()
              this.createtasksuccess = true
            }
            else this.createtaskfailed = true
          }).catch(error => {
            if (error.message.includes('timeout')) {
              this.requestState = true
            }
          });
        }
        else {
          console.log('error submit!!');
          return false;
        }
      })
    },
    createTask1() {
      var tasktype = 1
      if (this.choosed == 'one')
        tasktype = 1
      else tasktype = 2
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.createUserDialog = false
          var taskinfo = {
            type: tasktype,
            state: 3,
            workArea: {
              type: 1,
              area: [
                {
                  places: [
                    {
                      id: '',
                      name: '',
                      type: ''
                    }
                  ],
                  stationNo: '',
                  stationName: ''
                }
              ],
              areaKM: {
                start: {
                  kilo: '',
                  meter: ''
                },
                end: {
                  kilo: '',
                  meter: ''
                }
              },
              areaComment: '',
            },

            creater: {
              userId: 1, deviceInfo: {
                "type": "PC",
                "id": null,
              }
            },
            beginTime_plan: getFormatDateTime(this.ruleForm.date1),
            endTime_plan: getFormatDateTime(this.ruleForm.date2),
            manager: [],
            liaison: [],
            safeman: [],
            worker: [],
            fenceIds: [this.fenceid],
            workContent: this.one_input_1,
            comment: this.one_input_2
          }
          if (!this.fenceid)
            taskinfo.fenceIds = []
          if (this.ruleForm.area[0] == 0) {

            {
              for (var q = 0; q < this.station_lists_1[0].children.length; q++)
                if (this.station_lists_1[0].children[q].value == (this.ruleForm.area[1]))
                  var the_state = q

              for (var j = 0; j < this.station_lists_1[0].children[the_state].children.length; j++) {
                if (this.station_lists_1[0].children[the_state].children[j].value == (this.ruleForm.area[2])) {
                  taskinfo.workArea.type = this.station_lists_1[0].children[the_state].children[j].areaType

                  taskinfo.workArea.area[0].stationNo = this.station_lists_1[0].children[the_state].children[j].stationNo
                  taskinfo.workArea.area[0].stationName = this.station_lists_1[0].children[the_state].children[j].stationName
                  taskinfo.workArea.area[0].places[0].id = this.station_lists_1[0].children[the_state].children[j].value
                  taskinfo.workArea.area[0].places[0].name = this.station_lists_1[0].children[the_state].children[j].label
                  taskinfo.workArea.area[0].places[0].type = this.station_lists_1[0].children[the_state].children[j].type
                }
              }
            }
          }
          else if (this.ruleForm.area[0] == 1) {
            for (var q = 0; q < this.station_lists_1[1].children.length; q++)
              if (this.station_lists_1[1].children[q].value == (this.ruleForm.area[1])) {
                taskinfo.workArea.area = [
                  {
                    stations: [],
                    sectionId: '',
                  }
                ]
                taskinfo.workArea.type = 2

                taskinfo.workArea.area[0].sectionId = this.station_lists_1[1].children[q].value
                taskinfo.workArea.area[0].stations = this.station_lists_1[1].children[q].stations
              }
          }
          taskinfo.workArea.areaKM.start.kilo = this.start_kilometer_1
          taskinfo.workArea.areaKM.start.meter = this.start_meter_1
          taskinfo.workArea.areaKM.end.kilo = this.end_kilometer_1
          taskinfo.workArea.areaKM.end.meter = this.end_meter_1
          taskinfo.workArea.areaComment = this.location_supplied_1

          this.ruleForm.manager.forEach((item) => {

            if (item[item.length - 1].match('US'))
              taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
            else if (item[item.length - 1].match('UG'))
              taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
            else if (item[item.length - 1].match('DG'))
              taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
            else taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
          })
          this.ruleForm.liaison.forEach((item) => {

            if (item[item.length - 1].match('US'))
              taskinfo.liaison.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
            else if (item[item.length - 1].match('UG'))
              taskinfo.liaison.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
            else if (item[item.length - 1].match('DG'))
              taskinfo.liaison.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
            else taskinfo.liaison.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
          })
          this.ruleForm.safeman.forEach((item) => {

            if (item[item.length - 1].match('US'))
              taskinfo.safeman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
            else if (item[item.length - 1].match('UG'))
              taskinfo.safeman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
            else if (item[item.length - 1].match('DG'))
              taskinfo.safeman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
            else taskinfo.safeman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
          })
          this.ruleForm.worker.forEach((item) => {

            if (item[item.length - 1].match('US'))
              taskinfo.worker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
            else if (item[item.length - 1].match('UG'))
              taskinfo.worker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
            else if (item[item.length - 1].match('DG'))
              taskinfo.worker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
            else taskinfo.worker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
          })

          postTaskInfo(taskinfo).then((response) => {
            if (response.code == 0) {
              this.searchEvents2()
              this.createtasksuccess = true
            }

            else this.createtaskfailed = true
          }).catch(error => {
            if (error.message.includes('timeout')) {
              this.requestState = true
            }
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      })




    },


    updateTask3() {
      var tasktype = 4
      if (this.choosed == 'update_three')
        tasktype = 4
      else tasktype = 8
      this.autoCreateFenceDialog = false
      this.updateUserDialog = false
      var taskinfo = {
        type: tasktype,
        state: 3,
        workArea: {
          type: 1,
          area: [
            {
              places: [
                {
                  id: '',
                  name: '',
                  type: ''
                }
              ],
              stationNo: '',
              stationName: ''
            }
          ],
          areaComment: '',
        },

        creater: {
          userId: null, deviceInfo: {
            "type": "PC",
            "id": null,
          }
        },
        beginTime_plan: '',
        endTime_plan: '',
        manager: [],
        trainChecker: [],
        fenceIds: [this.fenceid_traincheck],
        workContent: this.three_input_1,
        comment: this.three_input_2
      }
      this.ruleForm.date1 = new Date(this.ruleForm.date1)
      this.ruleForm.date2 = new Date(this.ruleForm.date2)
      // taskinfo.beginTime_plan=getFormatDateTime_2(this.ruleForm.date1)
      // taskinfo.endTime_plan=getFormatDateTime_2(this.ruleForm.date2)
      // taskinfo.beginTime_plan='2023-03-05 18:02:06'
      // taskinfo.endTime_plan='2023-03-05 18:02:06'
      taskinfo.beginTime_plan = getFormatDateTime(this.ruleForm.date1)
      taskinfo.endTime_plan = getFormatDateTime(this.ruleForm.date2)
      if (!this.fenceid_traincheck)
        taskinfo.fenceIds = []
      if (this.ruleForm.area[0] == 0) {

        {
          for (var q = 0; q < this.station_lists_1[0].children.length; q++)
            if (this.station_lists_1[0].children[q].value == (this.ruleForm.area[1]))
              var the_state = q

          for (var j = 0; j < this.station_lists_1[0].children[the_state].children.length; j++) {
            if (this.station_lists_1[0].children[the_state].children[j].value == (this.ruleForm.area[2])) {
              taskinfo.workArea.type = this.station_lists_1[0].children[the_state].children[j].areaType

              taskinfo.workArea.area[0].stationNo = this.station_lists_1[0].children[the_state].children[j].stationNo
              taskinfo.workArea.area[0].stationName = this.station_lists_1[0].children[the_state].children[j].stationName
              taskinfo.workArea.area[0].places[0].id = this.station_lists_1[0].children[the_state].children[j].value
              taskinfo.workArea.area[0].places[0].name = this.station_lists_1[0].children[the_state].children[j].label
              taskinfo.workArea.area[0].places[0].type = this.station_lists_1[0].children[the_state].children[j].type
            }
          }
        }
      }
      taskinfo.workArea.areaComment = this.location_supplied_3
      this.ruleForm.manager.forEach((item) => {

        if (item[item.length - 1].match('US'))
          taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
        else if (item[item.length - 1].match('UG'))
          taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
        else if (item[item.length - 1].match('DG'))
          taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
        else taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
      })
      this.ruleForm.trainChecker.forEach((item) => {

        if (item[item.length - 1].match('US'))
          taskinfo.trainChecker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
        else if (item[item.length - 1].match('UG'))
          taskinfo.trainChecker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
        else if (item[item.length - 1].match('DG'))
          taskinfo.trainChecker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
        else taskinfo.trainChecker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
      })
      updateTaskInfo(this.edit_taskid, taskinfo).then((response) => {
        if (response.code == 0) {
          this.updatetasksuccess = true
          this.searchEvents2()
        }

        else this.updatetaskfailed = true
      }).catch(error => {
        if (error.message.includes('timeout')) {
          this.requestState = true
        }
      });
    },
    updateTask2() {
      var tasktype = 3
      if (this.choosed == 'update_two')
        tasktype = 3
      else tasktype = 5
      this.updateUserDialog = false
      var taskinfo = {
        type: tasktype,
        state: 3,
        workArea: {
          type: 0,
          area: [
            {
              places: [
                {
                  id: '',
                  name: '',
                  type: ''
                }
              ],
              stationNo: '',
              stationName: ''
            }
          ],
          areaComment: '',
        },

        creater: {
          userId: null, deviceInfo: {
            "type": "PC",
            "id": null,
          }
        },
        beginTime_plan: '',
        endTime_plan: '',

        manager: [],
        petrolman: [],
        workContent: this.two_input_1,
        comment: this.two_input_2
      }
      this.ruleForm.date1 = new Date(this.ruleForm.date1)
      this.ruleForm.date2 = new Date(this.ruleForm.date2)
      taskinfo.beginTime_plan = getFormatDateTime(this.ruleForm.date1)
      taskinfo.endTime_plan = getFormatDateTime(this.ruleForm.date2)
      // if(this.station_list2[0][0]==0)
      // {
      //   {
      //     for(var q=0;q<this.station_lists_1[0].children.length;q++)
      //     if(this.station_lists_1[0].children[q].value==(this.station_list2[0][1]))
      //     var the_state=q
      //     console.log(this.station_lists_1)
      //     for(var j=0;j<this.station_lists_1[0].children[the_state].children.length;j++)
      //     {
      //       if(this.station_lists_1[0].children[the_state].children[j].value==(this.station_list2[0][2]))
      //       {
      //         taskinfo.workArea.type=this.station_lists_1[0].children[the_state].children[j].areaType
      //         taskinfo.workArea.area[0].stationNo=this.station_lists_1[0].children[the_state].children[j].stationNo
      //         taskinfo.workArea.area[0].stationName=this.station_lists_1[0].children[the_state].children[j].stationName
      //         taskinfo.workArea.area[0].places[0].id=this.station_lists_1[0].children[the_state].children[j].value
      //         taskinfo.workArea.area[0].places[0].name=this.station_lists_1[0].children[the_state].children[j].label
      //         taskinfo.workArea.area[0].places[0].type=this.station_lists_1[0].children[the_state].children[j].type
      //       }
      //     }
      //   }
      // }
      taskinfo.workArea.areaComment = this.location_supplied_2
      this.ruleForm.manager.forEach((item) => {

        if (item[item.length - 1].match('US'))
          taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
        else if (item[item.length - 1].match('UG'))
          taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
        else if (item[item.length - 1].match('DG'))
          taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
        else taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
      })
      this.ruleForm.petrolman.forEach((item) => {

        if (item[item.length - 1].match('US'))
          taskinfo.petrolman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
        else if (item[item.length - 1].match('UG'))
          taskinfo.petrolman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
        else if (item[item.length - 1].match('DG'))
          taskinfo.petrolman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
        else taskinfo.petrolman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
      })
      updateTaskInfo(this.edit_taskid, taskinfo).then((response) => {
        if (response.code == 0) {
          this.updatetasksuccess = true
          this.searchEvents2()
        }

        else this.updatetaskfailed = true
      }).catch(error => {
        if (error.message.includes('timeout')) {
          this.requestState = true
        }
      });
    },
    updateTask1() {
      var tasktype = 1
      if (this.choosed == 'update_one')
        tasktype = 1
      else tasktype = 2
      this.updateUserDialog = false
      var taskinfo = {
        type: tasktype,
        state: 3,
        workArea: {
          type: 1,
          area: [
            {
              places: [
                {
                  id: '',
                  name: '',
                  type: ''
                }
              ],
              stationNo: '',
              stationName: ''
            }
          ],
          areaKM: {
            start: {
              kilo: '',
              meter: ''
            },
            end: {
              kilo: '',
              meter: ''
            }
          },
          areaComment: '',
        },

        creater: {
          userId: 1, deviceInfo: {
            "type": "PC",
            "id": null,
          }
        },
        beginTime_plan: isNaN(this.ruleForm.date1) ? getFormatDateTime(this.ruleForm.date1) : (this.ruleForm.date1),
        endTime_plan: isNaN(this.ruleForm.date2) ? getFormatDateTime(this.ruleForm.date2) : (this.ruleForm.date2),
        fenceIds: [this.fenceid],
        manager: [],
        liaison: [],
        safeman: [],
        worker: [],
        workContent: this.one_input_1,
        comment: this.one_input_2
      }
      this.ruleForm.date1 = new Date(this.ruleForm.date1)
      this.ruleForm.date2 = new Date(this.ruleForm.date2)
      if (!this.fenceid)
        taskinfo.fenceIds = []
      taskinfo.beginTime_plan = getFormatDateTime(this.ruleForm.date1)
      taskinfo.endTime_plan = getFormatDateTime(this.ruleForm.date2)
      if (this.ruleForm.area[0] == 0) {

        {
          for (var q = 0; q < this.station_lists_1[0].children.length; q++)
            if (this.station_lists_1[0].children[q].value == (this.ruleForm.area[1]))
              var the_state = q

          for (var j = 0; j < this.station_lists_1[0].children[the_state].children.length; j++) {
            if (this.station_lists_1[0].children[the_state].children[j].value == (this.ruleForm.area[2])) {
              taskinfo.workArea.type = this.station_lists_1[0].children[the_state].children[j].areaType

              taskinfo.workArea.area[0].stationNo = this.station_lists_1[0].children[the_state].children[j].stationNo
              taskinfo.workArea.area[0].stationName = this.station_lists_1[0].children[the_state].children[j].stationName
              taskinfo.workArea.area[0].places[0].id = this.station_lists_1[0].children[the_state].children[j].value
              taskinfo.workArea.area[0].places[0].name = this.station_lists_1[0].children[the_state].children[j].label
              taskinfo.workArea.area[0].places[0].type = this.station_lists_1[0].children[the_state].children[j].type
            }
          }
        }
      }
      else if (this.ruleForm.area[0] == 1) {
        for (var q = 0; q < this.station_lists_1[1].children.length; q++)
          if (this.station_lists_1[1].children[q].value == (this.ruleForm.area[1])) {
            taskinfo.workArea.area = [
              {
                stations: [],
                sectionId: '',
              }
            ]
            taskinfo.workArea.type = 2

            taskinfo.workArea.area[0].sectionId = this.station_lists_1[1].children[q].value
            taskinfo.workArea.area[0].stations = this.station_lists_1[1].children[q].stations
          }
      }
      taskinfo.workArea.areaKM.start.kilo = this.start_kilometer_1
      taskinfo.workArea.areaKM.start.meter = this.start_meter_1
      taskinfo.workArea.areaKM.end.kilo = this.end_kilometer_1
      taskinfo.workArea.areaKM.end.meter = this.end_meter_1
      taskinfo.workArea.areaComment = this.location_supplied_1

      this.ruleForm.manager.forEach((item) => {

        if (item[item.length - 1].match('US'))
          taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
        else if (item[item.length - 1].match('UG'))
          taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
        else if (item[item.length - 1].match('DG'))
          taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
        else taskinfo.manager.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
      })
      this.ruleForm.liaison.forEach((item) => {

        if (item[item.length - 1].match('US'))
          taskinfo.liaison.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
        else if (item[item.length - 1].match('UG'))
          taskinfo.liaison.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
        else if (item[item.length - 1].match('DG'))
          taskinfo.liaison.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
        else taskinfo.liaison.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
      })
      this.ruleForm.safeman.forEach((item) => {

        if (item[item.length - 1].match('US'))
          taskinfo.safeman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
        else if (item[item.length - 1].match('UG'))
          taskinfo.safeman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
        else if (item[item.length - 1].match('DG'))
          taskinfo.safeman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
        else taskinfo.safeman.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
      })
      this.ruleForm.worker.forEach((item) => {

        if (item[item.length - 1].match('US'))
          taskinfo.worker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'user' })
        else if (item[item.length - 1].match('UG'))
          taskinfo.worker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'userGroup' })
        else if (item[item.length - 1].match('DG'))
          taskinfo.worker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'deviceGroup' })
        else taskinfo.worker.push({ id: parseInt(item[item.length - 1].slice(2)), type: 'device' })
      })

      updateTaskInfo(this.edit_taskid, taskinfo).then((response) => {
        if (response.code == 0) {
          this.updatetasksuccess = true
          this.searchEvents2()
        }

        else this.updatetaskfailed = true
      }).catch(error => {
        if (error.message.includes('timeout')) {
          this.requestState = true
        }
      });
    },





    returntask() {
      this.openCheckFence = false
    },
    setfenceid(fenceid) {
      this.fenceid = fenceid
      this.openSelectFence = false
    },
    selectfence_fenceArea_create() {
      this.fenceid = this.selectFenceArea
      this.openSelectArea = false
    },
    selectfence_traincheck_create() {
      var data = {
        "fence_type": 1,
        "station_no": 1,
        "track_no": 1
      }
      if (this.selectFenceType == 1)
        data.fence_type = 0
      else data.fence_type = 1
      data.station_no = parseInt(this.ruleForm.area[1])
      data.track_no = parseInt(this.ruleForm.area[2])
      postfenceTrack(data).then((response) => {
        if (response.code == 0)
          this.fenceid = response.data.fence_id
        this.openSelectTrack = false
      }).catch(error => {
        if (error.message.includes('timeout')) {
          this.requestState = true
        }
      });
    },
    selectfence_traincheck() {
      var data = {
        "fence_type": 1,
        "station_no": 1,
        "track_no": 1
      }
      data.fence_type = 0
      data.station_no = parseInt(this.ruleForm.area[1])
      data.track_no = parseInt(this.ruleForm.area[2])
      postfenceTrack(data).then((response) => {
        if (response.code == 0) {
          this.autoCreateFence = false
          this.fenceid_traincheck = response.data.fence_id
        }


      }).catch(error => {
        if (error.message.includes('timeout')) {
          this.requestState = true
        }
      });
    },
    selectfence() {
      this.openFenceType = true
      // if(this.ruleForm.date1)
      // var ruleForm.date1=getFormatDateTime(this.ruleForm.date1)
      // if(this.switch_value1)
      // var switch_value1=getFormatDateTime(this.switch_value1)
      // if(this.ruleForm.date2)
      // var ruleForm.date2=getFormatDateTime(this.ruleForm.date2)
      // this.$router.push({name:'selectfence',query:{ruleForm.area:this.ruleForm.area,start_kilometer_1:this.start_kilometer_1,start_meter_1:this.start_meter_1,end_kilometer_1:this.end_kilometer_1,end_meter_1:this.end_meter_1,location_supplied_1:this.location_supplied_1,createUserDialog:this.createUserDialog,choosed:this.choosed,form_one:this.form_one,ruleForm.date1:ruleForm.date1,switch_value1:switch_value1,ruleForm.date2:ruleForm.date2,ruleForm.area:this.ruleForm.area,one_input_1:this.one_input_1,one_input_2:this.one_input_2,ruleForm.manager:this.ruleForm.manager,ruleForm.liaison:this.ruleForm.liaison,ruleForm.safeman:this.ruleForm.safeman,ruleForm.worker:this.ruleForm.worker}})
    },
    select_task_type() {
      {
        this.autoCreateFence = true
        this.getUserInfo(1, 100)
        this.getUserGroupInfo(1, 100)
        this.getDeviceInfo(1, 100)
        this.getDeviceGroupInfo(1, 100)
        if (this.form.region == '1')
          this.choosed = 'one'
        if (this.form.region == '2')
          this.choosed = 'two'
        if (this.form.region == '3')
          this.choosed = 'three'
        if (this.form.region == '4')
          this.choosed = 'four'
        if (this.form.region == '5')
          this.choosed = 'five'
        if (this.form.region == '8')
          this.choosed = 'eight'
      }
    },
    choose_select_way() {
      if (this.selectfence_way)
        this.openFenceType = false
      if (this.selectfence_way == 2)
        this.openSelectFence = true
      else if (this.selectfence_way == 1) {
        this.openSelectTrack = true
        this.selectFenceType = ''
      }
      else if (this.selectfence_way == 3) {
        getWorkAreaFence().then(response => {
          if (response.code == 0) {
            this.openSelectArea = true
            this.selectFenceArea = ''
            this.workAreaFenceMap = response.data
          }
        })

      }

    },
    filterglobalEventChange(column) {
      var deviceType = column['deviceType'][0];
      if (!deviceType) {
        this.globalEventTableData = this.globalEventTableDataAll
        this.totalDataLength = this.globalEventTableData.length
        return
      }
      else {
        this.globalEventTableData = this.globalEventTableDataAll.filter(function (value) {
          return value.deviceType == deviceType
        })
        this.totalDataLength = this.globalEventTableData.length
      }
    },
    async getUserInfo(page = null, size = null) {
      const msg = await getUserInfobyPage(page, 500)
      if (msg.code === 0) {

        var i = 0
        this.person_options_2[0] = {
          'value': 0,
          'label': '人员',
          'children': []
        }
        this.person_options[0] = {
          'value': 0,
          'label': '人员',
          'children': []
        }
        Array.from(msg.data.items, (item) => {
          this.person_options[0].children[i] = {
            'value': 1,
            'label': 1
          }
          this.person_options[0].children[i].value = 'US' + item.userId
          this.person_options[0].children[i].label = item.personName ? item.personName : item.userName
          i++
        })
        i = 0
        Array.from(msg.data.items, (item) => {
          this.person_options_2[0].children[i] = {
            'value': 1,
            'label': 1
          }
          this.person_options_2[0].children[i].value = 'US' + item.userId
          this.person_options_2[0].children[i].label = item.personName ? item.personName : item.userName
          i++
        })
        this.resetoptions++
      }
    },
    async getUserGroupInfo(page = null, size = null) {
      const msg = await getUserGroupInfobyPage(page, 500)
      if (msg.code === 0) {

        var i = 0
        this.person_options_2[1] = {
          'value': 1,
          'label': '人员组',
          'children': []
        }
        Array.from(msg.data.items, (item) => {
          this.person_options_2[1].children[i] = {
            'value': 1,
            'label': 1
          }
          this.person_options_2[1].children[i].value = 'UG' + item.groupId
          this.person_options_2[1].children[i].label = item.groupName
          i++
        })
        this.resetoptions++
      }
      return true
    },
    async getDeviceInfo(page = null, size = null) {
      const msg1 = await getDeviceInfobyPage(page, 200, 2) // 手持终端
      const msg2 = await getDeviceInfobyPage(page, 200, 3) // 定位终端
      if (msg1.code === 0 && msg2.code === 0) {

        var i = 0
        this.person_options[1] = {
          'value': 1,
          'label': '设备',
          'children': []
        }
        this.person_options[1].children[0] = {
          'value': 0,
          'label': '手持终端',
          'children': []
        }
        this.person_options[1].children[1] = {
          'value': 1,
          'label': '定位终端',
          'children': []
        }
        this.person_options_2[2] = {
          'value': 2,
          'label': '设备',
          'children': []
        }
        this.person_options_2[2].children[0] = {
          'value': 0,
          'label': '手持终端',
          'children': []
        }
        this.person_options_2[2].children[1] = {
          'value': 1,
          'label': '定位终端',
          'children': []
        }
        Array.from(msg1.data.items, (item) => {
          this.person_options_2[2].children[0].children[i] = {
            'value': 1,
            'label': 1
          }
          this.person_options_2[2].children[0].children[i].value = 'DE' + item.deviceId
          this.person_options_2[2].children[0].children[i].label = item.deviceName ? item.deviceName : `${item.deviceId}`
          i++
        })
        i = 0
        Array.from(msg2.data.items, (item) => {
          this.person_options_2[2].children[1].children[i] = {
            'value': 1,
            'label': 1
          }
          this.person_options_2[2].children[1].children[i].value = 'DE' + item.deviceId
          this.person_options_2[2].children[1].children[i].label = item.deviceName ? item.deviceName : `${item.deviceId}`
          i++
        })
        i = 0
        Array.from(msg1.data.items, (item) => {
          this.person_options[1].children[0].children[i] = {
            'value': 1,
            'label': 1
          }
          this.person_options[1].children[0].children[i].value = 'DE' + item.deviceId
          this.person_options[1].children[0].children[i].label = item.deviceName ? item.deviceName : `${item.deviceId}`
          i++
        })
        i = 0
        Array.from(msg2.data.items, (item) => {
          this.person_options[1].children[1].children[i] = {
            'value': 1,
            'label': 1
          }
          this.person_options[1].children[1].children[i].value = 'DE' + item.deviceId
          this.person_options[1].children[1].children[i].label = item.deviceName ? item.deviceName : `${item.deviceId}`
          i++
        })
        this.resetoptions++
      }
    },
    async getDeviceGroupInfo(page = null, size = null) {

      const msg = await getDeviceGroupInfobyPage(page, 500)
      if (msg.code === 0) {

        var i = 0
        this.person_options_2[3] = {
          'value': 3,
          'label': '设备组',
          'children': []
        }
        Array.from(msg.data.items, (item) => {
          this.person_options_2[3].children[i] = {
            'value': 1,
            'label': 1
          }
          this.person_options_2[3].children[i].value = 'DG' + item.groupId
          this.person_options_2[3].children[i].label = item.groupName
          i++
        })
        this.resetoptions++
      }

      return true
    },
    filterSingleEventChange(column) {
      var deviceType = column['deviceType'][0];
      if (!deviceType) {
        this.singleEventTableData = this.singleEventTableDataAll
        this.totalDataLength = this.singleEventTableDataAll.length
        return
      }
      else {
        this.singleEventTableData = this.singleEventTableDataAll.filter(function (value) {
          return value.deviceType == deviceType
        })
        this.totalDataLength = this.singleEventTableData.length
      }
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
      this.searchEvents2()
    },
    handleSizeChange: function (size) {
      this.pagesize = size
      this.searchEvents2()
    },
    searchEvents2() {
      this.loading = true

      // this.getEventHistory()
      // this.currentPage = 1
      // this.$refs.refsTable.clearFilter()
      this.timeRange = []
      // if(this.timeRanges[0]!=null)
      // this.timeRange[0]= this.timeRanges[0]
      // if(this.timeRanges[1]!=null) 
      // this.timeRange[1]= this.timeRanges[1]
      var data = {
        timeRange: this.timeRanges,
        state: this.choose_task_state,
        type: this.choose_task_type,
        timeType: this.choose_time_type,
        page: this.currentPage,
        pageSize: this.pagesize

      }

      if (data.timeRange != null && data.timeType == "") {
        this.TimeTypeError = true
        return false
      }
      if (data.timeRange == null && data.timeType != "") {
        this.TimeRangeError = true
        return false
      }
      if (!data.timeType)
        data = {
          state: this.choose_task_state,
          type: this.choose_task_type,
          page: this.currentPage,
          pageSize: this.pagesize
        }
      getTaskBriefList(data).then((response) => {
        if (response.code == 0) {
          this.tableData_length = response.data.total
          var tableData = []
          var i = 0
          for (i; i < response.data.item.length; i++) {
            tableData[i] =
            {
              picture_exist: 'unknown',
              fenceid: null,
              taskid: 1,
            }
            tableData[i].taskid = response.data.item[i].taskId
            if (response.data.item[i].type == 1)
              tableData[i].type = '工务作业'
            if (response.data.item[i].type == 3)
              tableData[i].type = '巡道作业'
            if (response.data.item[i].type == 5)
              tableData[i].type = '其它作业'
            if (response.data.item[i].type == 4)
              tableData[i].type = '列检作业'
            if (response.data.item[i].type == 2)
              tableData[i].type = '电务作业'
            if (response.data.item[i].type == 6)
              tableData[i].type = '机务作业'
            if (response.data.item[i].type == 7)
              tableData[i].type = '调车作业'
            if (response.data.item[i].type == 8)
              tableData[i].type = '商检作业'
            if (response.data.item[i].state == 3)
              tableData[i].state = "startTask"
            else if (response.data.item[i].state == 5)
              tableData[i].state = "endTask"
            else tableData[i].state = "overTask"
            if (response.data.item[i].fenceIds.length != 0)
              tableData[i].fenceid = response.data.item[i].fenceIds[0]
            if (response.data.item[i].beginTime != undefined) {
              tableData[i].beginTime = new Date(response.data.item[i].beginTime)
              tableData[i].beginTime = getFormatDateTime(tableData[i].beginTime)
            }
            else tableData[i].beginTime = "---      "
            if (response.data.item[i].endTime != undefined) {
              tableData[i].endTime = new Date(response.data.item[i].endTime)
              tableData[i].endTime = getFormatDateTime(tableData[i].endTime)
            }
            else tableData[i].endTime = " ---"
            if (response.data.item[i].beginTime_plan != undefined) {
              tableData[i].beginTime_plan = new Date(response.data.item[i].beginTime_plan)
              tableData[i].beginTime_plan = getFormatDateTime(tableData[i].beginTime_plan)
            }
            else tableData[i].beginTime_plan = "---                "
            if (response.data.item[i].endTime_plan != undefined) {
              tableData[i].endTime_plan = new Date(response.data.item[i].endTime_plan)
              tableData[i].endTime_plan = getFormatDateTime(tableData[i].endTime_plan)
            }
            else tableData[i].endTime_plan = " ---"

          }

          this.tableData = tableData
          for (var i = 0; i < this.tableData.length; i++) {
            const taskid = this.tableData[i].taskid
            getImagePaths(this.tableData[i].taskid).then(

              (response) => {
                for (var j = 0; j < this.tableData.length; j++)
                  if (this.tableData[j].taskid == taskid)
                    if (response.data[0]) {
                      this.tableData[j].picture_exist = 'true'
                    }
                    else this.tableData[j].picture_exist = 'false'

              }).catch(error => {
                if (error.message.includes('timeout')) {
                  this.requestState = true
                }
              });
          }
          this.twoData = tableData
        }

        else {
          this.gettaskfailed = true
          this.requestState = true
        }
        if (this.tableData_length != 0 && this.tableData.length == 0) {
          this.currentPage = 1
          this.searchEvents2()
        }
      }).catch(error => {
        if (error.message.includes('timeout')) {
          this.requestState = true
        }
      });

    },

    // async getEventChinese() {
    //   const res = await getEventChinese()
    //   this.eventNames = res
    // },
    // async getEventHistory() {
    //   this.globalEventTableData = []
    //   this.singleEventTableData = []
    //   await this.getEventDict()
    //   this.queryData.startTime = this.timeRanges[0].getTime()
    //   this.queryData.endTime = this.timeRanges[1].getTime()
    //   this.queryData.eventId = this.eventId
    //   const res = await getEventHistory(this.queryData)
    //   this.totalDataLength = res.data.length
    //   for (var i = 0; i < res.data.length; i++) {
    //     if (res.data[i].TWSEntityLoginExitEvent) {
    //       this.setLoginExitEvent(res, i, this.eventId)
    //     }
    //     if (res.data[i].NotMonitoredLocomotivesAddDelEvent) {
    //       this.setNotMonitoredLocomotivesAddDelEvent(res, i, this.eventId)
    //     }
    //     if (res.data[i].LocationSituationChangeEvent) {
    //       this.setLocationSituationChangeEvent(res, i, this.eventId)
    //     }
    //     if (res.data[i].PrewarnInfoChangeEvent) {
    //       this.setPrewarnInfoChangeEvent(res, i, this.eventId)
    //     }
    //     if (res.data[i].FenceRelationChangeEvent) {
    //       this.setFenceRelationChangeEvent(res, i, this.eventId)
    //     }
    //   }
    //   this.globalEventTableDataAll = this.globalEventTableData
    //   this.singleEventTableDataAll = this.singleEventTableData
    //   if (this.globalEventTableData.length != 0) {
    //     this.globalEventTableData.sort(
    //       function (a, b) {
    //         return a.appearTime < b.appearTime ? 1 : -1
    //       }
    //     )
    //   }
    //   if (this.singleEventTableData.length != 0) {
    //     this.singleEventTableData.sort(
    //       function (a, b) {
    //         return a.appearTime < b.appearTime ? 1 : -1
    //       }
    //     )
    //   }
    //   this.loading = false
    // },
    // async getEventDict() {
    //   const res = await getEventDict()
    //   this.eventDict = res
    //   this.setFilters(res)
    // },
    setFilters(res) {
      var filters = []
      for (var key in res.global.deviceType) {
        var filter = { 'text': res.global.deviceType[key], 'value': res.global.deviceType[key] }
        filters.push(filter)
      }
      this.filters = filters
    },
    setLoginExitEvent(res, i, eventId) {
      res.data[i].TWSEntityLoginExitEvent.deviceType = this.eventDict.global.deviceType[res.data[i].TWSEntityLoginExitEvent.deviceType];
      res.data[i].TWSEntityLoginExitEvent.eventType = this.eventDict.TWSEntityLoginExitEvent.eventType[res.data[i].TWSEntityLoginExitEvent.eventType];
      res.data[i].TWSEntityLoginExitEvent.eventReason = this.eventDict.TWSEntityLoginExitEvent.eventReason[res.data[i].TWSEntityLoginExitEvent.eventReason];
      if (eventId === 1) {
        var temp = {
          'appearTime': res.data[i].TWSEntityLoginExitEvent.appearTime, 'deviceId': res.data[i].TWSEntityLoginExitEvent.deviceId,
          'deviceType': res.data[i].TWSEntityLoginExitEvent.deviceType, 'descrption': res.data[i].TWSEntityLoginExitEvent.eventType + ',  原因：' + res.data[i].TWSEntityLoginExitEvent.eventReason
        }
        this.globalEventTableData.push(temp);
      }
      else {
        this.singleEventTableData.push(res.data[i].TWSEntityLoginExitEvent)
      }
    },
    setNotMonitoredLocomotivesAddDelEvent(res, i, eventId) {
      res.data[i].NotMonitoredLocomotivesAddDelEvent.deviceType = this.eventDict.global.deviceType[res.data[i].NotMonitoredLocomotivesAddDelEvent.deviceType];
      res.data[i].NotMonitoredLocomotivesAddDelEvent.eventType = this.eventDict.NotMonitoredLocomotivesAddDelEvent.eventType[res.data[i].NotMonitoredLocomotivesAddDelEvent.eventType];
      res.data[i].NotMonitoredLocomotivesAddDelEvent.eventReason = this.eventDict.NotMonitoredLocomotivesAddDelEvent.eventReason[res.data[i].NotMonitoredLocomotivesAddDelEvent.eventReason];
      // this.globalEventTableData.push(res.data[i].NotMonitoredLocomotivesAddDelEvent);
      if (eventId === 1) {
        if (res.data[i].NotMonitoredLocomotivesAddDelEvent.eventReason) {
          var temp = {
            'appearTime': res.data[i].NotMonitoredLocomotivesAddDelEvent.appearTime, 'deviceId': res.data[i].NotMonitoredLocomotivesAddDelEvent.deviceId,
            'deviceType': res.data[i].NotMonitoredLocomotivesAddDelEvent.deviceType, 'descrption': res.data[i].NotMonitoredLocomotivesAddDelEvent.eventType + ',  原因：' + res.data[i].NotMonitoredLocomotivesAddDelEvent.eventReason
          }
          this.globalEventTableData.push(temp);
        }
        else {
          var temp = {
            'appearTime': res.data[i].NotMonitoredLocomotivesAddDelEvent.appearTime, 'deviceId': res.data[i].NotMonitoredLocomotivesAddDelEvent.deviceId,
            'deviceType': res.data[i].NotMonitoredLocomotivesAddDelEvent.deviceType, 'descrption': res.data[i].NotMonitoredLocomotivesAddDelEvent.eventType
          }
          this.globalEventTableData.push(temp);
        }
      }
      else {
        this.singleEventTableData.push(res.data[i].NotMonitoredLocomotivesAddDelEvent)
      }
    },
    setLocationSituationChangeEvent(res, i, eventId) {
      res.data[i].LocationSituationChangeEvent.deviceType = this.eventDict.global.deviceType[res.data[i].LocationSituationChangeEvent.deviceType];
      res.data[i].LocationSituationChangeEvent.statusBeforeChanged = this.eventDict.LocationSituationChangeEvent.statusBeforeChanged[res.data[i].LocationSituationChangeEvent.statusBeforeChanged];
      res.data[i].LocationSituationChangeEvent.statusAfterChanged = this.eventDict.LocationSituationChangeEvent.statusAfterChanged[res.data[i].LocationSituationChangeEvent.statusAfterChanged];
      // this.globalEventTableData.push(res.data[i].LocationSituationChangeEvent);
      if (eventId === 1) {
        var temp = {
          'appearTime': res.data[i].LocationSituationChangeEvent.appearTime, 'deviceId': res.data[i].LocationSituationChangeEvent.deviceId,
          'deviceType': res.data[i].LocationSituationChangeEvent.deviceType, 'descrption': '变更前定位状态：' + res.data[i].LocationSituationChangeEvent.statusBeforeChanged + ',  变更后定位状态：' + res.data[i].LocationSituationChangeEvent.statusAfterChanged
        }
        this.globalEventTableData.push(temp);
      }
      else {
        this.singleEventTableData.push(res.data[i].LocationSituationChangeEvent)
      }
    },
    setPrewarnInfoChangeEvent(res, i, eventId) {
      res.data[i].PrewarnInfoChangeEvent.deviceType = this.eventDict.global.deviceType[res.data[i].PrewarnInfoChangeEvent.deviceType];
      if (eventId === 1) {
        var descrption = ''
        if (res.data[i].PrewarnInfoChangeEvent.preWarnsNumBeforeChanged == 0) {
          descrption = '产生预警'
        }
        if (res.data[i].PrewarnInfoChangeEvent.preWarnsNumAfterChanged == 0) {
          descrption = '预警消失'
        }
        var temp = {
          'appearTime': res.data[i].PrewarnInfoChangeEvent.appearTime, 'deviceId': res.data[i].PrewarnInfoChangeEvent.deviceId,
          'deviceType': res.data[i].PrewarnInfoChangeEvent.deviceType, 'descrption': descrption
        }
        this.globalEventTableData.push(temp);
      }
      else {
        this.singleEventTableData.push(res.data[i].PrewarnInfoChangeEvent)
      }
    },
    setFenceRelationChangeEvent(res, i, eventId) {
      res.data[i].FenceRelationChangeEvent.deviceType = this.eventDict.global.deviceType[res.data[i].FenceRelationChangeEvent.deviceType];
      res.data[i].FenceRelationChangeEvent.fenceRelationBeforeChanged = this.eventDict.FenceRelationChangeEvent.fenceRelationBeforeChanged[res.data[i].FenceRelationChangeEvent.fenceRelationBeforeChanged];
      res.data[i].FenceRelationChangeEvent.fenceRelationAfterChanged = this.eventDict.FenceRelationChangeEvent.fenceRelationAfterChanged[res.data[i].FenceRelationChangeEvent.fenceRelationAfterChanged];
      if (eventId === 1) {
        var temp = {
          'appearTime': res.data[i].FenceRelationChangeEvent.appearTime, 'deviceId': res.data[i].FenceRelationChangeEvent.deviceId, 'fence_id': res.data[i].FenceRelationChangeEvent.fence_id,
          'deviceType': res.data[i].FenceRelationChangeEvent.deviceType, 'descrption': '变更前与围栏的关系：' + res.data[i].FenceRelationChangeEvent.fenceRelationBeforeChanged + ',  变更后与围栏的关系：' + res.data[i].FenceRelationChangeEvent.fenceRelationAfterChanged
        }
        this.globalEventTableData.push(temp);
      }
      else {
        this.singleEventTableData.push(res.data[i].FenceRelationChangeEvent)
      }
    },
    add0(m) { return m < 10 ? '0' + m : m },
    format(timeStamp) {
      //shijianchuo是整数，否则要parseInt转换
      var time = new Date(timeStamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
      var y = time.getFullYear();
      var m = time.getMonth() + 1;
      var d = time.getDate();
      var h = time.getHours();
      var mm = time.getMinutes();
      var s = time.getSeconds();
      return y + '-' + this.add0(m) + '-' + this.add0(d) + ' ' + this.add0(h) + ':' + this.add0(mm) + ':' + this.add0(s);
    }
  }
}